(function() {
  'use strict';

  angular
    .module('hp')
    .factory('LoginService', Login)
    .factory('RegisterService', Register)
    .factory('MachineCodeService', MachineCode)
    .factory('UploadCodeService', UploadCode)
    .factory('PlayCodeService', PlayCode)
    .factory('ProvinceService', getProvince)
    .factory('CityService', getCity)
    .service('MyAuth', MyAuth)

    function Login($resource){
        return $resource('/api/userLogin', {}, {
            post:{method:'POST'}
        });
        // return $http.post('/api/userLogin');
    }

    function Register($resource){
        return $resource('/api/registConfirm', {}, {
            post:{method:'POST'}
        });
        // return $http.post('/api/registConfirm');
    }

    function MachineCode($resource){
        return $resource('/api/machineCodeList', {}, {
            query:{method:'POST'},
            // query:{method:'GET', isArray:true, params:{pageIndex:'@pageIndex',pageSize:'@pageSize',uid:'@uid'}},
            create:{method:'POST'},
            get:{method:'GET'},
            update:{method:'PUT'},
            del:{method:'DELETE'}
        });
        // return $http.post('/api/machineCodeList');
    }

    function UploadCode($resource){
        return $resource('/api/uploadMachineCode', {}, {
            post:{method:'POST'}
        });
        // return $http.post('/api/uploadMachineCode');
    }

    function PlayCode($resource){
        return $resource('/api/playCodeList', {}, {
            query:{method:'POST'}
        });
        // return $http.post('/api/playCodeList');
    }

    function getProvince($resource){
        return $resource('/api/getProvince', {}, {
            get:{method:'POST'}
        });
        // return $http.post('/api/getProvince');
    }

    function getCity($resource){
        return $resource('/api/getCitiesByProId', {}, {
            get:{method:'POST'}
        });
        // return $http.post('/api/getCitiesByProId');
    }

    function MyAuth($rootScope,$window){
        this.loggedIn = function(){
          return $window.sessionStorage.getItem('token')
          // return $cookies.get('token');
        };
        this.setData = function(name,value){
          $window.sessionStorage.setItem(name,value)
        };
        // this.setCookie = function(name,value,expireTime){
        // 	$cookies.put(name,value,{expires:new Date(expireTime)});
        // };
        this.Logout = function(){
          // $cookies.remove('token');
          $window.sessionStorage.removeItem('token')
        //   $rootScope.user = {};
          $rootScope.$broadcast('event:auth-require',true);
        };
    }

})();
